import Router from 'vue-router'
import Vue from 'vue'
import Home from '@/views/Home'
import Login from '@/views/Login'
import Welcome from '@/components/welcome/Welcome'

import User from "@/views/user/user"
import Role from "@/views/role/role"
import Permission from "@/views/permission/permission"
import ApiManage from "@/views/apiManage/apiManage"

import Article from "@/views/article/article"
import ArticleNote from "@/views/articleNote/articlenote"

/* 下面是为了解决Avoided redundant navigation to current location问题的，
    即点击当前nav页的时候，会提示上面的问题。具体原理我也不是特别懂，但是有用*/
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}



Vue.use(Router)
const router = new Router({
    routes: [
        {
            path: '/',
            redirect: '/home'
        }, {
            path: '/login',
            component: Login
        }, {
            path: '/home',
            component: Home,
            redirect: '/welcome',
            children: [
                {
                    path: '/welcome',
                    name: 'welcome',
                    component: Welcome,
                    meta: {
                        isTab: false,
                        title: "首页"
                    }
                }, {
                    path: '/user',
                    name: 'user',
                    component: User,
                    meta: {
                        isTab: true,
                        title: "用户管理"
                    }
                }, {
                    path: '/role',
                    name: 'role',
                    component: Role,
                    meta: {
                        isTab: true,
                        title: "角色管理"
                    }
                }, {
                    path: '/permission',
                    name: 'permission',
                    component: Permission,
                    meta: {
                        isTab: true,
                        title: "权限管理"
                    }
                }, {
                    path: '/apiManage',
                    name: 'apiManage',
                    component: ApiManage,
                    meta: {
                        isTab: true,
                        title: "接口管理"
                    }
                },
                {
                    path: "/article",
                    name: "article",
                    component: Article,
                    meta: {
                        isTab: true,
                        title: "文章管理"
                    }
                },
                {
                    path: "/articleNote",
                    name: "articleNote",
                    component: ArticleNote,
                    meta: {
                        isTab: true,
                        title: "留言管理"
                    }
                }
            ]
        }
    ]
})

export default router